<!DOCTYPE html>
<html>

<head>
    <meta name="layout" content="main2" />
    <g:set var="entityName" value="${message(code: 'activity.label', default: 'Activity')}" />
    <title>编辑预约</title>
</head>

<body>
    <div class="main-body">
        <div class="page-wrapper">
            <div class="page-header">
                <div class="page-header-title">
                    <h4>编辑预约</h4>
                </div>

                <div class="page-header-breadcrumb">
                    <ul class="breadcrumb-title">
                        <li class="breadcrumb-item">
                            <a href="/salesDashboard/index">
                                <i class="icofont icofont-home"></i>
                            </a>
                        </li>
                        <li class="breadcrumb-item">
                            <g:link controller="activity" action="index">预约</g:link>
                        </li>
                        <li class="breadcrumb-item">编辑预约</li>
                    </ul>
                </div>
            </div>

            <div class="page-body">
                <g:if test="${flash.message}">
                    <div class="message alert alert-info" role="status">${flash.message}
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span></button>
                    </div>
                </g:if>
                <g:hasErrors bean="${this.activity}">
                    <ul class="errors" role="alert">
                        <g:eachError bean="${this.activity}" var="error">
                            <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>>
                                <g:message error="${error}" />
                            </li>
                        </g:eachError>
                    </ul>
                </g:hasErrors>

                <div class="card">
                    <div class="card-header">
                        <h5>编辑预约</h5>

                        <div class="card-header-right">
                            <i class="icofont icofont-rounded-down"></i>
                        </div>
                    </div>

                    <div class="card-block">
                        <g:form resource="${this.activity}" method="PUT" class="form-horizontal">

                            <div class="form-group row">
                                <label class="col-md-2 col-form-label">商机编号</label>

                                <div class="col-md-3">
                                    <g:textField name="opportunity.id" id="opportunity" value="${this.activity?.opportunity?.id}" class="hide" />
                                    <g:textField name="opportunityName" value="${this.activity?.opportunity?.serialNumber}" disabled="" class="form-control" />
                                </div>
                                <label class="col-md-2 col-form-label is-required">状态</label>

                                <div class="col-md-3">
                                    <g:select id="status" disabled="" name='status' value="${this.activity?.status}" noSelection="${['': '请选择']}" from="${this.activity.constrainedProperties.status.inList}" class="form-control"></g:select>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-md-2 col-form-label">所有者</label>

                                <div class="col-md-3">
                                    <g:textField name="userName" value="${this.activity?.user?.fullName}" disabled="" class="form-control" />
                                </div>
                                <label class="col-md-2 col-form-label is-required">活动类型</label>

                                <div class="col-md-3">
                                    <g:select id="type" name='type.id' value="${this.activity?.type?.id}" noSelection="${['': '请选择']}" from='${com.next.ActivityType.list()}' optionKey="id" optionValue="name" class="form-control"></g:select>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-md-2 col-form-label is-required">子类型</label>

                                <div class="col-md-3">
                                    <g:select id="subtype" name='subtype.id' value="${this.activity?.subtype?.id}" noSelection="${['': '请选择']}" from='${com.next.ActivitySubtype.list()}' optionKey="id" optionValue="name" class="form-control"></g:select>
                                </div>
                                <label class="col-md-2 col-form-label">执行人</label>

                                <div class="col-md-3">
                                    <g:select id="assignedTo" name='assignedTo.id' value="${this.activity?.assignedTo?.id}" from='${com.next.User.list()}' optionKey="id" optionValue="fullName" noSelection="${['': '请选择']}" class="form-control"></g:select>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-md-2 col-form-label is-required">计划开始时间</label>

                                <div class="col-md-3 datePicker">
                                    %{--
                                    <g:datePicker name="startTime" value="${this.activity?.startTime}" precision="minute" />--}%
                                    <div class="input-group">
                                        <input type="text" valctrl="startTime" value="${this.activity?.startTime}" class="form-control form_datetime">
                                        <input type="hidden" id="startTime" name="startTime" value="date.struct">
                                        <input type="hidden" id="startTime_minute" name="startTime_minute" value="">
                                        <input type="hidden" id="startTime_hour" name="startTime_hour" value="">
                                        <input type="hidden" id="startTime_day" name="startTime_day" value="">
                                        <input type="hidden" id="startTime_month" name="startTime_month" value="">
                                        <input type="hidden" id="startTime_year" name="startTime_year" value="">
                                    </div>
                                </div>

                                <label class="col-md-2 col-form-label is-required">计划结束时间</label>

                                <div class="col-md-3 datePicker">
                                    %{-- <g:datePicker name="endTime" value="${this.activity?.endTime}" precision="minute" /> --}%
                                    <div class="input-group ">
                                        <input type="text" valctrl="endTime" value="${this.activity?.endTime}" class="form-control form_datetime">
                                        <input type="hidden" id="endTime" name="endTime" value="date.struct">
                                        <input type="hidden" id="endTime_minute" name="endTime_minute" value="">
                                        <input type="hidden" id="endTime_hour" name="endTime_hour" value="">
                                        <input type="hidden" id="endTime_day" name="endTime_day" value="">
                                        <input type="hidden" id="endTime_month" name="endTime_month" value="">
                                        <input type="hidden" id="endTime_year" name="endTime_year" value="">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-md-2 col-form-label">实际开始时间</label>
                                <div class="col-md-3 datePicker">
                                    %{-- <g:datePicker name="actualStartTime" value="${this.activity?.actualStartTime}" precision="minute" /> --}%
                                    <div class="input-group">
                                        <input type="text" valctrl="actualStartTime" value="${this.activity?.actualStartTime}" class="form-control form_datetime6">
                                        <input type="hidden" id="actualStartTime" name="actualStartTime" value="date.struct">
                                        <input type="hidden" id="actualStartTime_minute" name="actualStartTime_minute" value="">
                                        <input type="hidden" id="actualStartTime_hour" name="actualStartTime_hour" value="">
                                        <input type="hidden" id="actualStartTime_day" name="actualStartTime_day" value="">
                                        <input type="hidden" id="actualStartTime_month" name="actualStartTime_month" value="">
                                        <input type="hidden" id="actualStartTime_year" name="actualStartTime_year" value="">
                                    </div>
                                </div>

                                <label class="col-md-2 col-form-label">实际结束时间</label>

                                <div class="col-md-3 datePicker">
                                    %{-- <g:datePicker name="actualEndTime" value="${this.activity?.actualEndTime}" precision="minute" /> --}%
                                    <div class="input-group">
                                        <input type="text" valctrl="actualEndTime" value="${this.activity?.actualEndTime}" class="form-control form_datetime6">
                                        <input type="hidden" id="actualEndTime" name="actualEndTime" value="date.struct">
                                        <input type="hidden" id="actualEndTime_minute" name="actualEndTime_minute" value="">
                                        <input type="hidden" id="actualEndTime_hour" name="actualEndTime_hour" value="">
                                        <input type="hidden" id="actualEndTime_day" name="actualEndTime_day" value="">
                                        <input type="hidden" id="actualEndTime_month" name="actualEndTime_month" value="">
                                        <input type="hidden" id="actualEndTime_year" name="actualEndTime_year" value="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-2 col-form-label">描述</label>

                                <div class="col-md-8">
                                    <g:textArea rows="3" class="form-control" name="description" id="description" value="${this.activity?.description}" />
                                </div>
                            </div>

                            <g:if test="${this?.displayRating}">
                                <div class="form-group row">
                                    <label class="col-md-2 col-form-label">评分</label>

                                    <div class="col-md-3">
                                      <g:select id="rating" name='rating' value="${this.activity?.rating}" noSelection="${['': '请选择']}" from="${1..10}" class="form-control"></g:select>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="col-md-2 col-form-label">备注</label>

                                    <div class="col-md-8">
                                        <g:textArea rows="3" class="form-control" name="memo" id="memo" value="${this.activity?.memo}" />
                                    </div>
                                </div>
                            </g:if>

                            <div class="form-group row">
                                <div class="col-md-12">
                                    <g:submitButton class="btn btn-info" name="update" value="保存" />
                                </div>
                            </div>
                        </g:form>

                    </div>
                </div>
            </div>

        </div>
    </div>



<script>
    $(function () {
        $('.form_datetime6').datetimepicker({
            minView: "day",
            //选择日期后，不会再跳转去选择时分秒
            format: "yyyy-mm-dd hh:00",
            //选择日期后，文本框显示的日期格式
            language: 'zh-CN',
            //汉化
            autoclose: true //选择日期后自动关闭
        }).on('changeDate', function (ev) {
            var self = $(ev.currentTarget);
            // var valctrl = $("#"+self.attr("valctrl"));
            var valctrl_mm = $("#" + self.attr("valctrl") + "_minute");
            var valctrl_h = $("#" + self.attr("valctrl") + "_hour");
            var valctrl_d = $("#" + self.attr("valctrl") + "_day");
            var valctrl_m = $("#" + self.attr("valctrl") + "_month");
            var valctrl_y = $("#" + self.attr("valctrl") + "_year");
            var mdate = moment(ev.date.valueOf());
            // valctrl.val(mdate.format("YYYY-MM-DD"));
            // valctrl_mm.val(mdate.format("m"));
            valctrl_mm.val("00");
            valctrl_h.val(mdate.format("HH"));
            valctrl_d.val(mdate.format("D"));
            valctrl_m.val(mdate.format("M"));
            valctrl_y.val(mdate.format("YYYY"));
        });
        $('.form_datetime6').each(function (index) {
            var self = $(this);
            var mdate = moment();
            debugger
            var tdatetime = self.val();
            if (tdatetime != "") {
                // mdate = moment(tdatetime);
                if (tdatetime.indexOf("CST") != -1)
                {
                  mdate = moment.parseZone(tdatetime).zone(6);
                }
                else
                {
                  mdate = moment(tdatetime);
                }

                var valctrl_mm = $("#" + self.attr("valctrl") + "_minute");
                var valctrl_h = $("#" + self.attr("valctrl") + "_hour");
                var valctrl_d = $("#" + self.attr("valctrl") + "_day");
                var valctrl_m = $("#" + self.attr("valctrl") + "_month");
                var valctrl_y = $("#" + self.attr("valctrl") + "_year");
                // valctrl_mm.val(mdate.format("m"));
                valctrl_mm.val("00");
                valctrl_h.val(mdate.format("HH"));
                valctrl_d.val(mdate.format("D"));
                valctrl_m.val(mdate.format("M"));
                valctrl_y.val(mdate.format("YYYY"));
                self.val(mdate.format('YYYY-MM-DD HH:00'));
            }

        });
    })
</script>
</body>

</html>
